|
|
|
|
|
|
|
Then use the PaintPicture method to copy the result into a visible picture box for the user to see. By changing the size of the visible picture box and using PaintPicture to stretch the preview image to fit, you can generate previews at different scales. Example program HiRes, described at the end of this chapter, demonstrates this technique. |
|
|
|
|
|
|
|
|
Previewing text is slightly harder because the fonts provided by your printer and your screen are probably different. Even if you select the same font name and size on your preview picture box and on the printer, you are unlikely to get identical results. For example, in one test using 20 point Arial, the system gave the preview picture box 20.25 point Arial and it gave the printer 19.92 point Arial. This made the preview look slightly different from the final printed result. |
|
|
|
|
|
|
|
|
These effects are most noticeable for very long text when differences between the picture box and the printer can accumulate. The final pages in multipage documents may look quite different when previewed and printed. The following section discusses multipage print preview and explains a method for making previews agree more closely with printed results. |
|
|
|
|
|
|
|
|
Generating a print preview for multiple pages of output is conceptually simple. The program uses the techniques described in the previous section to generate previews for each of the pages. If each page's output is independent of the others, that is easy. When each page's output depends on the output of the previous pages, however, this can be tricky. |
|
|
|
|
|
|
|
|
For example, the WordWrap program, described earlier in this chapter, prints a large amount of text. When the text extends past the right margin, the program starts a new line. When the text extends beyond the bottom margin, the program begins a new page. It is not obvious where a page begins unless you have already printed the previous pages. That makes printing or previewing an arbitrary page difficult. |
|
|
|
|
|
|
|
|
One solution is to modify the printing subroutine so that it produces output for pages within a specified range. The routine can still use the Printer object's CurrentX and CurrentY methods to position text. It can also use the Print method to print blank strings. It should not use Print to display text, however, unless it is on one of the selected pages. For other pages, it should use the TextWidth function to calculate the width of the text and then add that value to the printer's CurrentX property. |
|
|
|
|
|
|
|
|
Similarly, the routine should not invoke the Printer object's NewPage method unless it has just finished printing one of the selected pages. For other pages, it should simply reset the printer's CurrentX and CurrentY properties to start a new page. |
|
|
|
|
|
|
|
|
Note that the printing routine can follow these same steps while generating output on a picture box. Then the program can use the techniques described in the previous section to provide a print preview of arbitrary pages of output. |
|
|
|
|
|
|
|
|
As is mentioned in the previous section, differences in the font selected by the preview picture box and the printer can make a big difference in previewed and printed results for long documents. To keep the two as similar as possible, the output routine can use |
|
|
|
|
|